package com.example.drink_order_system.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;

import com.example.drink_order_system.R;

import DataBase.UserDbHelper;

public class forgetPassword extends AppCompatActivity {
    private EditText reset_name;
    private EditText reset_pass;
    private EditText confirm_reset_pass;
    private AppCompatButton reset_btn;
    private ImageButton back;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.forget_pass_layout);
        reset_name = findViewById(R.id.reset_name);
        reset_pass = findViewById(R.id.reset_pass);
        confirm_reset_pass = findViewById(R.id.confirm_reset_pass);
        reset_btn = findViewById(R.id.reset_btn);
        back = findViewById(R.id.forgetPass_back);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        reset_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (reset_name.getText().toString().equals("")||reset_pass.getText().toString().equals("")){
                    Toast.makeText(getApplication(),"信息不能为空！",Toast.LENGTH_SHORT).show();
                }else if (reset_pass.getText().toString().equals(confirm_reset_pass.getText().toString())){
                    String username = reset_name.getText().toString();
                    String password = reset_pass.getText().toString();
                    UserDbHelper db = (UserDbHelper) UserDbHelper.getSqliteHelper(getApplication());
                    db.reset_info(username,password);
                    finish();
                    Toast.makeText(getApplication(),"重置成功！请重新登录！",Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(getApplication(),"两次输入的密码不一致！",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
